package cate.game.pvp;

import cate.game.db.mongo.kv.KvMongo;
import easy.java.dev.note.NoteField;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * PVP排行加成存储KV
 *
 * @author ShenSL
 * @since 2023/9/15 15:32
 */
@Slf4j
public class PvpRankRewardExtraKV extends KvMongo {
    @NoteField("UID -> 历史最大星级")
    public Map<String, Integer> uidToStarMax = new HashMap<>();

    @Override
    public String getKeyPrefix() {
        return KEY_PVP_RANK_REWARD_EXTRA;
    }

    public void eat(PvpRankRewardExtraKV food) {
        if(food == null || food.uidToStarMax == null) {
            return;
        }
        try {
            food.uidToStarMax.forEach((k, v) -> {
                this.uidToStarMax.put(k, v);
            });
        } catch (Exception e) {
            log.error("", e);
        }
    }

    public void initialize() {
        if (uidToStarMax == null) {
            uidToStarMax = new HashMap<>();
        }
    }

    public void updateStarMax(String uid, int star) {
        synchronized (this) {
            uidToStarMax.put(uid, star);
        }
    }
}
